#!/usr/bin/python
# -*- coding: UTF-8 -*-
#https://wxpy.readthedocs.io/zh/latest/messages.html#id11

from wxpy import *
import re
# 初始化机器人，扫码登陆
bot = Bot(True,True)

# 机器人账号自身
myself = bot.self

bot.enable_puid('wxpy_puid.pkl')

# 打印来自其他好友、群聊和公众号的消息
@bot.register()
def print_others(msg):
    print(msg)

#好友申请
@bot.register(Friend,FRIENDS)
def print_others(msg):
    print(msg)

#群消息
@bot.register(Group)
def print_others(msg):
    print('群聊消息-->>')
    print(msg)

#普通聊天信息
@bot.register(Friend, TEXT)
def print_friend_msg(msg):
    print(msg)
    try:
        if '8'==msg.text:
                return '菜单：\r 8：获取最新菜单\r 7：获取本店资质材料\r 6：获取下注流程图\r'
        elif '7'==msg.text:
                msg.chat.send_file('./img/彩店资质.png')
        elif '6'==msg.text:
                msg.chat.send_file('./img/流程介绍.png')
        else:return '无法识别的命令，请重新输入'
    except ResponseError as e:
        print(e.err_code, e.err_msg) # 查看错误号和错误消息

#投注单信息
@bot.register(Friend, SHARING)
def print_tzd_msg(msg):
    #typee = re.sub(r'(.*$', "", msg)
    print(msg)
    if ('投注单' in msg.text) :
        print('有新订单啦~~~~~~~~~~~~~~~~')


# addfriend_request = '加好友'  #自动添加好友的条件
# 注册好友请求类消息
@bot.register(msg_types=FRIENDS,enabled=True)
# 自动接受验证信息中包含 'wxpy' 的好友请求
def auto_accept_friends(msg):
    # 判断好友请求中的验证文本
    if True: #addfriend_request in msg.text.lower():
        # 接受好友 (msg.card 为该请求的用户对象)
        new_friend = bot.accept_friend(msg.card)
        # 或 new_friend = msg.card.accept()
        # 向新的好友发送消息
        new_friend.send('欢迎光临本店，祝您一路长红！红红火火！')
        new_friend.send_file('./img/彩店资质.png')
        new_friend.send_file('./img/流程介绍.png')


# 进入 Python 命令行、让程序保持运行
bot.join()